package edu.sctu.zhuyingzhi.month201505.day20150504.exception.judgeArray;

import javax.swing.*;

/**
 * Created by user13 on 2015/5/4.
 */
public class JudgeArray {

    public void array() {
        int inputvalue, i;
        String input;
        int array[];
        do {
            input = JOptionPane.showInputDialog("请输入长度");
            inputvalue = Integer.parseInt(input);

            try {
                array = new int[inputvalue];

                for (i = 0; i < 5; i++) {
                    System.out.println("输出：" + array[i] + "   i=" + i);

                }

               /* throw new NegativeArraySizeException("array size is negative.");*/

            }
            catch (NegativeArraySizeException e) {

                System.out.println("catch exception.");
                JOptionPane.showMessageDialog(null, "数组长度为负数 不符合要求");

            }
            catch (ArrayIndexOutOfBoundsException f) {
                JOptionPane.showMessageDialog(null, "数组长度越界 不符合要求");
            }

        } while (inputvalue < 5);
        JOptionPane.showMessageDialog(null, "数组的长度是：" + inputvalue, "数值长度是", JOptionPane.INFORMATION_MESSAGE);
    }



}

